package de.hwr.sudokuspielehr.io;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.Test;

import de.hwr.sudokuspielehr.exception.UnknownSyntaxException;

/**
 * 
 * @author J. Reischauer
 * 
 */
public class TestParser {
	@Test
	public void test_parse() throws IOException, UnknownSyntaxException {
		File fileUnderTest = new File("TestParserTestFile.ssf");

		Map<String, Object> expected = new HashMap<String, Object>();
		expected.put("a", "1");
		expected.put("b", "2");
		expected.put("c", "1,2,3,4");
		expected.put("d", "hello world");
		expected.put("e", "some text");

		Map<String, String> actual = Parser.parse(Reader.read(fileUnderTest));

		assertEquals(expected.entrySet().size(), actual.entrySet().size());

		for (Entry<String, Object> expectedEntry : expected.entrySet()) {
			String expectedKey = expectedEntry.getKey();
			Object expectedValue = expectedEntry.getValue();

			assertTrue(actual.containsKey(expectedKey));
			assertEquals(expectedValue, actual.get(expectedKey));
		}
	}
}
